package com.start.common.tools;

import lombok.Getter;


public class CustomPage {
    @Getter
    private int startIndex;
    @Getter
    private int endIndex;
    @Getter
    private int total;
    @Getter
    private int size;
    @Getter
    private int current;

    private CustomPage() {
    }

    public static CustomPage calculation(int current, int size, int total) {

        if (current < 1) current = 1;
        if (size < 1) size = 1;
        int startIndex = (current - 1) * size;
        int endIndex = startIndex + size;
        if (endIndex >= total) endIndex = total;
        CustomPage customPage = new CustomPage();
        customPage.current = current;
        customPage.size = size;
        customPage.endIndex = endIndex;
        customPage.total = total;
        customPage.startIndex = startIndex;
        return customPage;
    }
}
